import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:schedule_self_client/api/schedule_self_server/task.dart';
import 'package:schedule_self_client/common/serializers.dart';

part 'task_list_resp.g.dart';

abstract class TaskListResp
    implements Built<TaskListResp, TaskListRespBuilder> {
  TaskListResp._();

  factory TaskListResp([void Function(TaskListRespBuilder) updates]) =
      _$TaskListResp;

  bool get success;

  String? get errCode;

  String? get errMessage;

  int get totalCount;

  int get pageSize;

  int get pageIndex;

  BuiltList<Task> get data;

  String toJson() {
    return jsonEncode(serializers.serializeWith(TaskListResp.serializer, this));
  }

  static TaskListResp? fromJson(String jsonString) {
    return serializers.deserializeWith(
        TaskListResp.serializer, jsonDecode(jsonString));
  }

  static Serializer<TaskListResp> get serializer => _$taskListRespSerializer;
}
